﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:componentModel="clr-namespace:System.ComponentModel;assembly=WindowsBase"
    xmlns:fontFamilyPicker="clr-namespace:Glass.Basics.Controls.FontFamilyPicker"
    xmlns:local="clr-namespace:Glass.Basics.Controls.EditableTextBlock">
        
    <ResourceDictionary.MergedDictionaries>
       
    </ResourceDictionary.MergedDictionaries>

    <Style TargetType="{x:Type local:EditableTextBlock}">
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:EditableTextBlock}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid>
                            <TextBlock Focusable="False" Text="{Binding Path=Text, RelativeSource={RelativeSource TemplatedParent}}" />
                            <TextBox x:Name="PART_TextBox" Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, ValidatesOnExceptions=True, RelativeSource={RelativeSource TemplatedParent}}" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEditing" Value="True">
                            <Setter TargetName="PART_TextBox" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsEditing" Value="False">
                            <Setter TargetName="PART_TextBox" Property="Visibility" Value="Hidden" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type fontFamilyPicker:FontFamilyPicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type fontFamilyPicker:FontFamilyPicker}">
                    <Grid>
                        <Grid.Resources>
                            <CollectionViewSource 
                                x:Key="Cvs" 
                                Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=FontFamilies}">
                                <CollectionViewSource.SortDescriptions>
                                    <componentModel:SortDescription PropertyName="Source" />
                                </CollectionViewSource.SortDescriptions>
                            </CollectionViewSource>
                        </Grid.Resources>
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ComboBox
                                SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SelectedFontFamily, Mode=TwoWay}"
                                ItemsSource="{Binding Source={StaticResource Cvs}}">
                            </ComboBox>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
